////////////////////////////////////////////////////////////////////////////////
// Copyright 2006 CORE Solutions Limited
// All rights reserved.
// PROPRIETARY AND CONFIDENTIAL INFORMATION.
// Use is subject to license terms.
//
// FUNCTION ID      :   REMARK
// AUTHOR           :   Ric Yik 
// DATE CREATE      :   2006/01/05
// DESCRIPTION      :   a MAINTENANCE FORM file for the function, REMARK
//                  :   
//                  :   
//                  :   
//
// MODIFICATION HISTORY:
// DATE         AUTHOR          VERSION NO.         COMMENT
// -----------  --------------  ------------------  -------------------
// 2006/01/05   Ric Yik         1.0                 source is generated.
//
//
//
////////////////////////////////////////////////////////////////////////////////

package com.erp.app.setup.remark.web;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.erp.app.common.util.ProjectCommonUtil;
import com.erp.app.util.web.ActionErrorUtil;
import com.erp.app.util.web.WebUtil;
import com.erp.framework.controller.form.SimpleMaintStyleForm;
import com.erp.framework.util.CommonUtil;
import com.erp.framework.util.logger.Logger;

/**
* <p>A <strong>MaintenanceForm</strong> is a JavaBean which provides property
* getter and setter methods for all of the bean properties, and implements
* <code>Serializable</code>, as required by the JavaBean specification
* The main purpose for this bean is to get the user input
* from the web browsers.
*
* @author          Ric Yik 
* @version 1.0     2006/01/05
* @since           FrameWork 1.0
*
*/
public class RemarkMaintenanceForm extends SimpleMaintStyleForm {

	//Header Attributes (DB Table Name: T_REMARK_HDR)
	private String companyCode;                      //DB Column Name: COMPANY_CODE
	private String remarkMasterCode;                 //DB Column Name: REMARK_MASTER_CODE
	private String remarkMasterDesc;                 //DB Column Name: REMARK_MASTER_DESC
	private String status;                           //DB Column Name: STATUS
	private String dcInd;                            //DB Column Name: DC_IND
	private String dcDate;                           //DB Column Name: DC_DATE
	private String createUser;                       //DB Column Name: CREATE_USER
	private String createDate;                       //DB Column Name: CREATE_DATE
	private String updateUser;                       //DB Column Name: UPDATE_USER
	private String updateDate;                       //DB Column Name: UPDATE_DATE

	//Child Attributes (DB Table Name: T_REMARK_DTL)
	private String[] remarkDtlCode;                  //DB Column Name: REMARK_DTL_CODE
	private String[] dtlRemark;                      //DB Column Name: REMARK
	private String[] dtlStatus;                      //DB Column Name: STATUS
	private String[] dtlIsDefault;                   //DB Column Name: IS_DEFAULT
	private String[] dtlDcInd;                       //DB Column Name: DC_IND
	private String[] dtlDcDate;                      //DB Column Name: DC_DATE

	/**
	* Validate the properties that have been set for this non-HTTP request,
	* and return an <code>ActionErrors</code> object that encapsulates any
	* validation errors that have been found.  If no errors are found, return
	* <code>null</code> or an <code>ActionErrors</code> object with no
	* recorded error messages.
	* <p>
	* The default implementation attempts to forward to the HTTP version of
	* this method.
	*
	* @param      the action errors array
	* @author     Ric Yik 
	* @since      FrameWork 1.0
	*/
	public void otherValidate(ActionErrors errors) {

		validateHdr(errors);
		validateDtl(errors);
	}

	/**
	* Validate the properties that have been set for this non-HTTP request,
	* and return an <code>ActionErrors</code> object that encapsulates any
	* validation errors that have been found.  If no errors are found, return
	* <code>null</code> or an <code>ActionErrors</code> object with no
	* recorded error messages.
	* <p>
	* The default implementation attempts to forward to the HTTP version of
	* this method.
	*
	* @param      errors The errors array that is used for storing validation errors
	* @author     Ric Yik 
	* @since      FrameWork 1.0
	*/
	public void validateHdr(ActionErrors errors) {
        WebUtil.validateCode(this.getCompanyCode(), "Company Code", errors);
        if (CommonUtil.isEmpty(this.getRemarkMasterCode())) {
        	ActionErrorUtil.addErrorForGeneralFieldBlank(errors, "Remarks Master Code");
        } else {
        	WebUtil.validateCode(this.getRemarkMasterCode(), "Remark Master Code", errors);
        }
    }

	/**
	* Validate the properties that have been set for this non-HTTP request,
	* and return an <code>ActionErrors</code> object that encapsulates any
	* validation errors that have been found.  If no errors are found, return
	* <code>null</code> or an <code>ActionErrors</code> object with no
	* recorded error messages.
	* <p>
	* The default implementation attempts to forward to the HTTP version of
	* this method.
	*
	* @param      errors The errors array that is used for storing validation errors
	* @author     Ric Yik 
	* @since      FrameWork 1.0
	*/
	public void validateDtl(ActionErrors errors) {
		ArrayList dtlRowList = getMultiRows(RemarkMaintenanceAction.TAB_IDX_DTL);
        int defaultCount = 0;
		for (int i = 0; (dtlRowList != null) && (i < dtlRowList.size()); ++i) {
			RemarkDtlRow row = (RemarkDtlRow) dtlRowList.get(i);
			if (WebUtil.isValidationSkippable(row)) continue;
			if (CommonUtil.isEmpty(row.getRemarkDtlCode())) {
            	ActionErrorUtil.addErrorForGeneralFieldBlank(errors, "Remarks Detail Code");
            } else {
            	WebUtil.validateCode(row.getRemarkDtlCode(), "Remarks Detail Code", errors);
            }
            if (row.isDtlDefault() && defaultCount <= 1) {
                ++defaultCount;
                if (defaultCount > 1) {
                	//TODO: fix later
//                    ActionErrorUtil.addErrorForGeneral(errors, "Only 1 Remarks Detail can be default.");
                }
            }
		}
	}

	/**
	* Validate the properties that have been set for this non-HTTP request,
	* and return an <code>ActionErrors</code> object that encapsulates any
	* validation errors that have been found.  If no errors are found, return
	* <code>null</code> or an <code>ActionErrors</code> object with no
	* recorded error messages.
	* <p>
	* The default implementation attempts to forward to the HTTP version of
	* this method.
	*
	* @param      mapping      the action mapping
	* @param      formIn       the action form
	* @param      request      the http request
	* @param      response     the http response
	* @param      errors       the action errors array
	* @author     Ric Yik 
	* @since      FrameWork 1.0
	*/
	public void moreValidate(ActionMapping mapping, ActionForm formIn,
		HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

		HttpSession session = request.getSession(false);
		RemarkMaintenanceForm form = (RemarkMaintenanceForm) formIn;

		try {

		} catch (Exception e) {
			Logger.logExceptions(this, e);
		}
	}

	/**
	* Reset all bean properties to their default state.  This method
	* is called inside the reset() method.
	*
	* @param      mapping The mapping used to select this instance
	* @param      request The servlet request we are processing
	* @author     Ric Yik 
	* @since      FrameWork 1.0
	*/
	public void otherReset(ActionMapping mapping, HttpServletRequest request) {
		
	}

	/**
	* Converts to a string representing the data in this object.
	* A new <code>String</code> object is allocated and initialized to 
	* contain the character sequence currently represented by this 
	* object. This <code>String</code> is then returned. Subsequent 
	* changes to this object do not affect the contents of the 
	* <code>String</code>. 
	*
	* @return     a string representation of the object.
	* @see        java.lang.Object#toString()
	* @author     Ric Yik 
	* @since      FrameWork 1.0
	*/
	public String toString() {
		String pkStr = "PK: {companyCode = " + this.companyCode
			+ "\n, remarkMasterCode = " + this.remarkMasterCode + "}\n";
		String colStr = "COL: {remarkMasterDesc = " + this.remarkMasterDesc
			+ "\n, status = " + this.status
			+ "\n, dcInd = " + this.dcInd
			+ "\n, dcDate = " + this.dcDate
			+ "\n, createUser = " + this.createUser
			+ "\n, createDate = " + this.createDate
			+ "\n, updateUser = " + this.updateUser
			+ "\n, updateDate = " + this.updateDate + "}\n";
		return "RemarkMaintenanceForm.toString() (header only) is:\n" + pkStr + colStr;
	}

	////////////////////////////////////////////////////////////////////////////////
	//Generated Accessors (get/set methods) for Header (RemarkHdr)
	////////////////////////////////////////////////////////////////////////////////

	public String getCompanyCode() {
		return this.companyCode;
	}

	public String getRemarkMasterCode() {
		return this.remarkMasterCode;
	}

	public String getRemarkMasterDesc() {
		return this.remarkMasterDesc;
	}

	public String getStatus() {
		return this.status;
	}

	public String getDcInd() {
		return this.dcInd;
	}

	public String getDcDate() {
		return this.dcDate;
	}

	public String getCreateUser() {
		return this.createUser;
	}

	public String getCreateDate() {
		return this.createDate;
	}

	public String getUpdateUser() {
		return this.updateUser;
	}

	public String getUpdateDate() {
		return this.updateDate;
	}

	public void setCompanyCode(String companyCode) {
		this.companyCode = ProjectCommonUtil.toCode(companyCode);
	}

	public void setRemarkMasterCode(String remarkMasterCode) {
		this.remarkMasterCode = ProjectCommonUtil.toCode(remarkMasterCode);
	}

	public void setRemarkMasterDesc(String remarkMasterDesc) {
		this.remarkMasterDesc = remarkMasterDesc;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public void setDcInd(String dcInd) {
		this.dcInd = dcInd;
	}

	public void setDcDate(String dcDate) {
		this.dcDate = dcDate;
	}

	public void setCreateUser(String createUser) {
		this.createUser = createUser;
	}

	public void setCreateDate(String createDate) {
		this.createDate = createDate;
	}

	public void setUpdateUser(String updateUser) {
		this.updateUser = updateUser;
	}

	public void setUpdateDate(String updateDate) {
		this.updateDate = updateDate;
	}

	////////////////////////////////////////////////////////////////////////////////
	//Generated Accessors (get/set methods) for Child (RemarkDtl)
	////////////////////////////////////////////////////////////////////////////////

	public String[] getRemarkDtlCode() {
		return this.remarkDtlCode;
	}

	public String[] getDtlRemark() {
		return this.dtlRemark;
	}

	public String[] getDtlStatus() {
		return this.dtlStatus;
	}

	public String[] getDtlIsDefault() {
		return this.dtlIsDefault;
	}

	public String[] getDtlDcInd() {
		return this.dtlDcInd;
	}

	public String[] getDtlDcDate() {
		return this.dtlDcDate;
	}

	public void setRemarkDtlCode(String[] remarkDtlCode) {
		this.remarkDtlCode = remarkDtlCode;
	}

	public void setDtlRemark(String[] dtlRemark) {
		this.dtlRemark = dtlRemark;
	}

	public void setDtlStatus(String[] dtlStatus) {
		this.dtlStatus = dtlStatus;
	}

	public void setDtlIsDefault(String[] dtlIsDefault) {
		this.dtlIsDefault = dtlIsDefault;
	}

	public void setDtlDcInd(String[] dtlDcInd) {
		this.dtlDcInd = dtlDcInd;
	}

	public void setDtlDcDate(String[] dtlDcDate) {
		this.dtlDcDate = dtlDcDate;
	}

	////////////////////////////////////////////////////////////////////////////////
	//Other Accessors (get/set methods)
	////////////////////////////////////////////////////////////////////////////////


}